<?php
class ControllerCalendar extends ControllerMain implements iController
{		
	protected $year;
	protected $month;	
	protected $appointment;
	protected $appointments = array();
	protected $days = array();

	public function index()
	{
		$this->validateTimeRequest();
		$this->calendar = new Calendar($this->year,$this->month);
		$this->navigation();
		$this->calendar();
	}
	
	private function navigation()
	{
		$this->keys = $this->calendar->getNavigation();
		$this->keys['number'] = BOARDROOM_NUMBER;
		$this->template = View::create($this->templateDir.'navigation.html',$this->keys);
		View::assign('content',$this->template);
		unset($this->keys);
		unset($this->template);
	}
	
	private function calendar()
	{
		$this->keys = $this->calendar->getCalendar();
		$this->template = View::create($this->templateDir.'calendar.html',$this->keys);
		View::assign('content',$this->template);
		unset($this->keys);
		unset($this->template);
	}
	
	private function validateTimeRequest()
	{
		if(!empty($this->get['year']) && !empty($this->get['month']))
		{
			$this->get['year'] = (int) $this->get['year'];
			$this->get['month'] = (int) $this->get['month'];
			if($this->get['year'] < 1972 || $this->get['year'] > 2037)
			{
				$this->year = date('Y',time());
			}
			else
			{
				$this->year = $this->get['year'];
			}
			if($this->get['month'] > 12 || $this->get['month'] < 1)
			{
				$this->month = date('n',time());
			}
			else
			{
				$this->month = $this->get['month'];
			}	
		}
		else
		{
			$this->year = date('Y',time());
			$this->month = date('n',time());
		}
	}	
}